local gushou = fk.CreateSkill{
  name = "gushou",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["gushou"] = "固守",
  [":gushou"] = "锁定技，每种牌名限一次，当你使用牌时，摸一张牌，然后下次伤害结算伤害-1。",
  ["@gushou"] = "固守"
}

gushou:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(gushou.name) and not data.card:isVirtual() and
    data.extra_data and data.extra_data.gushou
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, gushou.name)
    player.room:addPlayerMark(player, "@gushou", 1)
  end,

  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(gushou.name, true) and
      not table.contains(player:getTableMark(gushou.name), data.card.trueName)
  end,

  on_refresh = function (self, event, target, player, data)
    player.room:addTableMark(player, gushou.name, data.card.trueName)
    data.extra_data = data.extra_data or {}
    data.extra_data.gushou = true
  end,
})

gushou:addEffect(fk.DamageCaused, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@gushou") > 0
  end,
  on_use = function(self, event, target, player, data)
    data:changeDamage(-player:getMark("@gushou"))
    player.room:setPlayerMark(player, "@gushou", 0)
  end,
})

gushou:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@gushou") > 0
  end,
  on_use = function(self, event, target, player, data)
    data:changeDamage(-player:getMark("@gushou"))
    player.room:setPlayerMark(player, "@gushou", 0)
  end,
})

gushou:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, gushou.name, 0)
end)

return gushou